#include "mycanvasjulia.h"


MyCanvasJulia::MyCanvasJulia(QWidget *parent) : MyCanvas(parent)
{
    this->c=new Complex(-1.3,0.00525);
}

void MyCanvasJulia::paintEvent(QPaintEvent* pEvent)
{

    int p=30;
    QPainter painter(this);
    QSize size = this->size();
    Complex c2(c->real, c->imaginario);
    painter.fillRect(0,0,size.width(), size.height(), Qt::black);
    painter.setPen(Qt::red);
    for(int x=0;x<this->size().width();x++)
    {
        for(int y=0;y<this->size().height();y++)
        {
            double xfuncion=x_funcion(x,&this->size());
            double yfuncion=y_funcion(y,&this->size());
            Complex q(xfuncion,yfuncion);
            for(int i=1;i<=p;i++)
            {
                Complex qnuevo=q*q+c2;
                if(qnuevo.moduloALa2()>4)
                {
                    painter.setPen(QColor((255/p)*i,0,0));
                    painter.drawPoint(x,y);
                    break;
                }
                q=qnuevo;
            }
        }
    }

}

MyCanvasJulia::~MyCanvasJulia()
{
    delete c;
}
